package com.chaoyong.higo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import com.chaoyong.higo.R;
import com.chaoyong.higo.base.BaseAdapter;
import com.chaoyong.higo.bean.NewShareBean_z;
import com.chaoyong.higo.bean.TestNewsetBean;
import com.chaoyong.higo.bean.WiningGoodsBean;
import com.chaoyong.higo.utils.DataTimeTools;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.utils.ViewHolder;
import com.chaoyong.higo.view.CustomDigitalClock;
import com.chaoyong.higo.view.CustomDigitalClock.ClockListener;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 显示“最新揭晓”页面内容的adapter
 * 
 * @author zk
 *
 */
public class NewsetContentAdapter extends BaseAdapter<WiningGoodsBean.DataEntity.ListEntity> {

	/** 正在揭晓 */
	private ImageView iv_newset_tips;
	/** 限购 */
	private ImageView iv_newset_limits;
	/**用户头像*/
	private ImageView userHeadImg;
	/** 商品图片 */
	private ImageView iv_newset_image;
	/** 获得者 */
	private TextView newset_goods_name;
	/** 用户名 */
	private TextView newset_user_name;
	/** 参与人数 */
	private TextView newset_how_times;
	/** 价格 */
	private TextView newset_goods_price;
	/** 揭晓时间 */
	private TextView newset_details_time;
	/** 倒计时 */
	private CustomDigitalClock newset_counts;

	/** “参与人次”的布局 */
	private LinearLayout newset_times_layout;
	/** "揭晓时间"的布局 */
	private LinearLayout newset_date_layout;

	public NewsetContentAdapter(Context context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_newset_goods, null);
		}

		getView(convertView);
		
		//商品id
		String goods_id = mList.get(position).getGoods_id();
		//商品名
		String goods_name = mList.get(position).getGoods_name();
		//商品描述
		String goods_price = mList.get(position).getGoods_price();
		//揭晓时间
		String lottery_time = mList.get(position).getLottery_time();
		//用户名
		String user_name = mList.get(position).getUser_name();
		String expect = mList.get(position).getBuy_num();
		List<String> uri = mList.get(position).getCover_img();
		String headImg = mList.get(position).getUid_portrait();
		
		newset_user_name.setText(user_name);
		newset_how_times.setText(expect);
		newset_goods_price.setText(goods_price);
		newset_details_time.setText(DataTimeTools.time2(lottery_time));
		ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL +uri.get(0), iv_newset_image);
		ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL + headImg, userHeadImg);
		
		/**
		 * 有倒计时时候，只显示商品名称、商品价格及倒计时
		 * 没有倒计时时候，需要显示获得者名字、参与人次、商品价格、揭晓时间
		 */
		//TODO 这个接口还没调试
//		String uri = mList.get(position).getGoodsImage();
//		ImageLoader.getInstance().displayImage(uri, iv_newset_image);
		
//		String detail = mList.get(position).getGoodsDetails();
//		newset_goods_name.setText(detail);
//		
//		long tiems = mList.get(position).getCustomClock();
//		newset_counts.setEndTime(tiems);
		
//		newset_counts.setClockListener(new ClockListener() {
//			
//			@Override
//			public void timeEnd() {
//				
//			}
//			
//			@Override
//			public void remainFiveMinutes() {
//				
//			}
//		});
		return convertView;
	}

	/**
	 * 获取view
	 * 
	 * @param v
	 */
	private void getView(View v) {
		iv_newset_tips = ViewHolder.get(v, R.id.iv_newset_tips);
		iv_newset_limits = ViewHolder.get(v, R.id.iv_newset_limits);
		iv_newset_image = ViewHolder.get(v, R.id.iv_newset_image);
		newset_goods_name = ViewHolder.get(v, R.id.newset_goods_name);
		newset_user_name = ViewHolder.get(v, R.id.newset_user_name);
		newset_how_times = ViewHolder.get(v, R.id.newset_how_times);
		newset_goods_price = ViewHolder.get(v, R.id.newset_goods_price);
		newset_details_time = ViewHolder.get(v, R.id.newset_details_time);
		newset_times_layout = ViewHolder.get(v, R.id.newset_times_layout);
		newset_date_layout = ViewHolder.get(v, R.id.newset_date_layout);
		newset_counts = ViewHolder.get(v, R.id.newset_counts);
		userHeadImg = ViewHolder.get(v, R.id.newset_user_headimage);
	}

}
